import { DataType } from "./type";
import type { TableProps } from "antd";
import { Space, Popconfirm, Tag } from "antd";

export default function getColumns(
  handleClone: (id: number) => void,
  handlePull: (id: number) => void,
  handleInstall: (id: number) => void,
  handleDeploy: (id: number) => void,
  handleModify: (values: any) => void,
  handleDelete: (id: number) => void
): TableProps<DataType>["columns"] {
  return [
    {
      title: "项目名称",
      dataIndex: "project_name",
      minWidth: 140,
    },
    {
      title: "项目描述",
      dataIndex: "project_description",
      minWidth: 140,
    },
    {
      title: "克隆状态",
      dataIndex: "git_clone_status",
      minWidth: 100,
      render: (value) => {
        return (
          <Tag color={value ? "processing" : "error"}>
            {["未克隆", "已克隆"][value]}
          </Tag>
        );
      },
    },
    {
      title: "安装状态",
      dataIndex: "install_status",
      minWidth: 100,
      render: (value) => {
        return (
          <Tag color={value ? "success" : "error"}>
            {["未安装", "已安装"][value]}
          </Tag>
        );
      },
    },
    {
      title: "所属分支",
      dataIndex: "git_branch_name",
      minWidth: 100,
    },
    {
      title: "仓库地址",
      dataIndex: "repository_address",
      minWidth: 200,
    },
    {
      title: "安装路径",
      dataIndex: "install_path",
      minWidth: 100,
    },
    {
      title: "部署路径",
      dataIndex: "deploy_path",
      minWidth: 100,
    },
    {
      title: "构建文件夹名",
      dataIndex: "build_folder_name",
      minWidth: 120,
    },
    {
      title: "部署文件夹名",
      dataIndex: "deploy_folder_name",
      minWidth: 120,
    },
    {
      title: "安装命令",
      dataIndex: "install_command",
      minWidth: 120,
    },
    {
      title: "构建命令",
      dataIndex: "build_command",
      minWidth: 120,
    },
    {
      title: "创建时间",
      dataIndex: "create_time",
      minWidth: 160,
    },
    {
      title: "修改时间",
      dataIndex: "modify_time",
      minWidth: 160,
    },
    {
      title: "操作",
      key: "action",
      fixed: "right",
      minWidth: 200,
      render: (_, record) => (
        <Space size="middle">
          {record.install_status === 1 && (
            <a onClick={() => handleDeploy(record.id)}>部署</a>
          )}
          {record.git_clone_status === 0 && (
            <a onClick={() => handleClone(record.id)}>克隆</a>
          )}
          {record.git_clone_status === 1 && (
            <a onClick={() => handlePull(record.id)}>拉取</a>
          )}
          {record.git_clone_status === 1 && record.install_status === 0 && (
            <a onClick={() => handleInstall(record.id)}>安装</a>
          )}
          <a onClick={() => handleModify(record)}>修改</a>
          <Popconfirm
            title="提示"
            description="确定要删除吗？"
            okText="确定"
            cancelText="取消"
            onConfirm={() => handleDelete(record.id)}
          >
            <a>删除</a>
          </Popconfirm>
        </Space>
      ),
    },
  ];
}
